package com.wyu.test.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class JsonCode<T> {

    public static class ResponseBean<T>{
        private Integer status;
        private Integer error_code;
        private String error_message;
        private T data;

        public Integer getStatus() {
            return status;
        }

        public void setStatus(Integer status) {
            this.status = status;
        }

        public Integer getError_code() {
            return error_code;
        }

        public void setError_code(Integer error_code) {
            this.error_code = error_code;
        }

        public String getError_message() {
            return error_message;
        }

        public void setError_message(String error_message) {
            this.error_message = error_message;
        }

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }
    }


    public String ResponseFail(int ErrorCode, String ErrorMessage) {
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setError_code(ErrorCode);
        responseBean.setError_message(ErrorMessage);
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm").create();
        return gson.toJson(responseBean);
    }

    public String ResponseSuccess(T data) {
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setData(data);
        responseBean.setError_code(0);
        responseBean.setError_message("");
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm").create();
        return gson.toJson(responseBean);
    }

    public String ResponseSuccess() {
        ResponseBean<T> responseBean = new ResponseBean<T>();
        responseBean.setData(null);
        responseBean.setError_code(0);
        responseBean.setError_message("");
        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm").create();
        return gson.toJson(responseBean);
    }

}
